#include "Audio.h"
#include "DTMF.h"

/**
 * For each DTMF key a new pipeline is generated.
 *
 * The detected key is compared with the generated one, the test return
 * a success if every key is correctly detected.
 *
 * @pipeline{DTMF->DTMF_Detector}
 *
 * @return
 *         0: SUCCESS
 *         1: FAILURE
 **/
int main(int argc, char** argv) {
    int ret_code = 0;

    DSP* dsp;
    for (int i=0; i<4; i++) {
        for (int j=0; j<3; j++) {
            dsp = new DSP();

            char key = DTMF_KEYS[i][j];
            dsp->add((Module*)new DTMF(dsp->getSampleRate(), 0.5, key));

            DTMF_Detector* detector = new DTMF_Detector(dsp->getSampleRate());
            dsp->add((Module*)detector);

            Audio(dsp, 0.2);

            char detected = detector->detected();
            if (key == detected) {
                printf("[SUCCESS] Detected [%c]\n", detected);
            } else {
                printf("[FAILURE] Detected [%c] instead of [%c]", detected, key);
                ret_code = 1;
            }

            delete dsp;
        }
    }

    return ret_code;
}
